"""
主流程调度脚本
- 包含开始/结束提示、时间统计、进度条逻辑
"""

import time
from tqdm import tqdm
import yaml
import matplotlib.pyplot as plt
from src.aux_utils import aux_des_workflow
from netcore import fill_mode, preprocess_city_df

if __name__ == "__main__":
    plt.rcParams['font.sans-serif'] = ['Heiti TC']
    plt.rcParams['axes.unicode_minus'] = False
    print("="*40)
    start_time_str = time.strftime('%Y-%m-%d %H:%M:%S')
    start_time = time.time()
    print(f"⏱ 程序开始运行 {start_time_str}")
    print("="*40)

    # 读取 config.yaml
    with open("config.yaml", "r", encoding="utf-8") as f:
        config = yaml.safe_load(f)

    # 示例：调用新函数
    # 假设有 DataFrame df 和 columns 列表
    # df = fill_mode(df, columns)
    # df = preprocess_city_df(df)
    # 其余流程...
    steps = [
        "数据加载与预处理",
        "描述性统计与可视化",
        "方差分析（ANOVA）",
        "分组对比分析",
        "主成分分析（PCA）与 cohort 统计"
    ]
    for i, step in enumerate(tqdm(steps, desc="总流程进度", ncols=80, bar_format='{l_bar}\033[33m{bar}\033[0m| {n_fmt}/{total_fmt}')):
        if i == 0:
            pass  # 数据加载在 aux_des_workflow 内部
        elif i == 1:
            pass  # 描述性统计在 aux_des_workflow 内部
        elif i == 2:
            pass  # 方差分析在 aux_des_workflow 内部
        elif i == 3:
            pass  # 分组对比分析在 aux_des_workflow 内部
        elif i == 4:
            aux_des_workflow(config)

    end_time_str = time.strftime('%Y-%m-%d %H:%M:%S')
    end_time = time.time()
    print("="*40)
    print(f"⌛️ 程序运行结束 {end_time_str}")
    duration = end_time - start_time
    print(f"总耗时：{int(duration)} 秒（{duration/60:.2f} 分钟）")
    print("="*40)
